package com.railway.field.controller;

import com.railway.field.page.JsonResult;
import com.railway.field.service.StaffService;
import com.railway.field.util.ProvinceUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

@Api(description = "员工接口")
@RestController
@RequestMapping("Staff")
@CrossOrigin
public class StaffController {
    @Autowired
    private StaffService staffService;//员工

    //@Autowired
    //private WorktypeService worktypeService;//工种

    //@Autowired
    //private CodeService codeService;//验证码

    @ApiOperation(value = "手动输入增加员工信息/身份证读卡器识别" , notes = "")
    @PostMapping("/InsertStaff_Map")
    public JsonResult InsertStaff_Map(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();
        if(!map.get("staff_address").equals("")){
            map.put("staff_province" , ProvinceUtil.Province((String) map.get("staff_address")));
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        String time = format.format(now);
        map.put("entry_time",time);
        int i = staffService.InsertStaff_Map(map);
        if(i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("人员录入成功");
            return jsonResult;
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("人员录入失败");
            return jsonResult;
        }
    }


}
